#' ---
#' title: "Greenwashing the Future? Computational Text Analysis of Environmental Reporting from the Fossil Fuel Industry"
#' subtitle: "03_calculate_FLS_score.R"
#' author: "Robin Rauner"
#' date: "Note: Code compiled successfully on `r format(Sys.time(), '%d %B %Y')`"
#' ---

# load packages
library(tidyverse) # CRAN v2.0.0

sessionInfo()

# load data
dat_llm_annotated <- read.csv("llm_annotated_data.csv") |> 
  rename(doc_id = speech_id)

dat_messages <- read.csv("messages_text_corpus.csv") |> 
  select(-X)

# merge company names from text corpus

dat_llm_annotated <- dat_llm_annotated |> 
  left_join(dat_messages, by = "doc_id")

###### COMPANY-LEVEL SCORES ######

# calculate percentage of 1s per company
dat_fls_scores <- dat_llm_annotated |> 
  group_by(company) |> 
  summarize(fls_score = sum(fls) / n())

# save
write.csv(dat_fls_scores, "fls_scores_llm.csv")
